<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // 苹果3元一个，鸭梨2元一个，桃子1元一个。现在想用200元正好买100个水果，在控制台中列出所有可能性。

    var appleMax = parseInt(200 / 3),
    pearMax = 200 / 2,
    peachMax = 200
    apple: for (var i = 0; i <= appleMax; i++) {
      pear: for (var j = 0; j <= pearMax; j++) {
        if (i + j === 100 && 3 * i + 2 * j === 200) {
            console.log(i, j, 0)
            break pear
          }
        peach: for (var k = 0; k <= peachMax; k++) {
          if (i + j + k === 100 && 3 * i + 2 * j + k === 200) {
            console.log(i, j, k)
            break pear
          }
        }
      }
    }
  </script>
</body>
</html>